package work.lianwei;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import com.azure.storage.blob.BlobServiceClientBuilder;
import com.azure.storage.blob.specialized.BlockBlobClient;
import com.azure.storage.common.StorageSharedKeyCredential;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author Gong.Yang
 */
public class Test {
    public static void main(String[] args) {
//        // 填写您的 Azure Storage 账户信息
//        String accountName = "your_storage_account_name";
//        String accountKey = "your_storage_account_key";
//        String containerName = "your_container_name";
//        String blobName = "your_blob_name";
//        String filePath = "";
//        File file = FileUtil.file(filePath);
//
//        // 创建 StorageSharedKeyCredential 对象
//        StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
//
//        // 创建 BlobServiceClientBuilder 对象
//        BlobServiceClientBuilder builder = new BlobServiceClientBuilder()
//                .endpoint("https://" + accountName + ".blob.core.windows.net")
//                .credential(credential);
//
//        // 创建 BlockBlobClient 对象
//        BlockBlobClient blockBlobClient = builder
//                .buildClient()
//                .getBlobContainerClient(containerName)
//                .getBlobClient(blobName)
//                .getBlockBlobClient();
//
//        String fileName = file.getName();
//
//        FileInputStream fileStream = new FileInputStream(filePath.toString());
//        List<String> blockIDArrayList = new ArrayList<>();
//        byte[] buffer = new byte[blockSize];
//        int bytesRead;
//
//        while ((bytesRead = fileStream.read(buffer, 0, blockSize)) != -1) {
//
//            try (ByteArrayInputStream stream = new ByteArrayInputStream(buffer)) {
//                String blockID = Base64.getEncoder().encodeToString(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8));
//
//                blockIDArrayList.add(blockID);
//                blobClient.stageBlock(blockID, stream, buffer.length);
//            }
//        }
//
//        blobClient.commitBlockList(blockIDArrayList);
//
//        fileStream.close();
    }



}
